package com.lss233.recipeguide.executor;

import com.lss233.recipeguide.RecipeGuide;
import com.lss233.recipeguide.Storage;
import com.lss233.recipeguide.listener.GuiAddListener;
import com.lss233.recipeguide.listener.GuiMenuListener;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;

/**
 * @author Lss233
 */
public class RecipeExecutor implements CommandExecutor {
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(!(sender instanceof Player)) return false;
        if(args.length == 0){
            return false;
        }else {
            if (args[0].equalsIgnoreCase("new") && sender.hasPermission("lss233.recipe.new")) {

                Inventory inv = Bukkit.getServer().createInventory(null, 54, "  ===-= Create a new recipe guide.");
                GuiAddListener.getOpeningMap().put((Player) sender, inv);
                ((Player) sender).openInventory(inv);
                return true;
            }else if (args[0].equalsIgnoreCase("gui") && sender.hasPermission("lss233.recipe.gui")) {
                Inventory inv = Bukkit.getServer().createInventory(null, 54, "  ===-= Select a item.");
                GuiMenuListener.getOpeningMap().put((Player) sender, inv);
                ((Player) sender).openInventory(inv);
                return true;
            }else if (args[0].equalsIgnoreCase("reload") && sender.hasPermission("lss233.recipe.gui")) {
                Storage.reload();
                RecipeGuide.getInstance().reloadConfig();
                sender.sendMessage("[RecipeGuide]Reloaded.");
                return true;
            }
        }
        return false;
    }
}
